﻿package plugin.activity.handler
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.global.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import pluginfw.nio.*;
    import pluginfw.nio.imsg.*;

    public class ActivityHandler extends Object implements IGroupHandler
    {
        private var _timeID:uint = 0;

        public function ActivityHandler()
        {
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            switch(param1.getCmd())
            {
                case CMDActivity.Error:
                {
                    ModelProxy.change("movetips", "error", param1.getParam());
                    break;
                }
                case CMDActivity.QianDao:
                {
                    ModelProxy.change("data", "roledata.qd", param1.getParam());
                    ModelProxy.change("activity", "qiandao", param1.getParam());
                    ModelProxy.change("mainui", "refreshOnlineBtn", null);
                    break;
                }
                case CMDActivity.Guide:
                {
                    ModelProxy.change("data", "xinshou", param1.getParam());
                    ModelProxy.change("activity", "xinshou", param1.getParam());
                    break;
                }
                case CMDActivity.LingQu:
                {
                    ModelProxy.change("data", "roledata.qdlq", param1.getParam());
                    ModelProxy.change("activity", "lingqu", param1.getParam());
                    break;
                }
                case CMDActivity.VipReward:
                {
                    ModelProxy.change("movetips", "error", "已经全部领取VIP礼包");
                    _loc_3 = UserData.getOnlineData();
                    _loc_3.viprewad = param1.getParam();
                    ModelProxy.change("data", "roledata", _loc_3);
                    break;
                }
                case CMDActivity.VipUpdate:
                {
                    _loc_3 = UserData.getOnlineData();
                    _loc_4 = param1.getParam();
                    _loc_3.money = _loc_4.money;
                    if (_loc_4.vip > _loc_3.vip)
                    {
                        ModelProxy.change("movetips", "error", "你的VIP等级提升到" + _loc_4.vip);
                        PluginManager.instance.openPlugin("vip", new Point(100, 100));
                    }
                    _loc_3.vip = _loc_4.vip;
                    ModelProxy.change("data", "roledata", _loc_3);
                    break;
                }
                case CMDActivity.ChengZhangGet:
                {
                    ModelProxy.change("activity", "czget", param1.getParam());
                    break;
                }
                case CMDActivity.ChongJiGet:
                {
                    ModelProxy.change("cefenghuodong", "cjget", param1.getParam());
                    break;
                }
                case CMDActivity.GetChengZhang:
                {
                    ModelProxy.change("activity", "getcz", param1.getParam());
                    break;
                }
                case CMDActivity.GetChongJi:
                {
                    ModelProxy.change("cefenghuodong", "getcj", param1.getParam());
                    break;
                }
                case CMDActivity.GetZaiXian:
                {
                    ModelProxy.change("activity", "getzx", param1.getParam());
                    break;
                }
                case CMDActivity.Email:
                {
                    ModelProxy.change("chat", "addsysmsg", "活动信息拦截，有问题需修复，发现者提bug。");
                    ModelProxy.change("mainui", "showemail", null);
                    break;
                }
                case CMDActivity.Shouji:
                {
                    ModelProxy.change("plugin", "close", "shoujiyanzheng");
                    break;
                }
                case CMDActivity.GetFcActInfo:
                {
                    ModelProxy.change("cefenghuodong", "getdata", param1.getParam());
                    break;
                }
                case CMDActivity.GetQrylRews:
                {
                    _loc_2 = param1.getParam();
                    _loc_3 = UserData.getOnlineData();
                    ModelProxy.change("data", "logindaycount", _loc_2[0]);
                    _loc_3.qryl = _loc_2[1];
                    ModelProxy.change("dzp", "updateDayRew", null);
                    ModelProxy.change("mainui", "wdfl", null);
                    ModelProxy.change("mainui", "wdgd", null);
                    break;
                }
                case CMDActivity.OldFlash:
                {
                    _loc_3 = UserData.getOnlineData();
                    _loc_3.flashplayer = 1;
                    ModelProxy.change("flashupdate", "update", null);
                    break;
                }
                case CMDActivity.GetFlashPlayerRews:
                {
                    _loc_3 = UserData.getOnlineData();
                    _loc_3.flashplayer = 2;
                    ModelProxy.change("flashupdate", "update", null);
                    if (this._timeID > 0)
                    {
                        clearInterval(this._timeID);
                        this._timeID = 0;
                    }
                    break;
                }
                case CMDActivity.GetLiXian:
                {
                    ModelProxy.change("activity", "GetLiXian", param1.getParam());
                    ModelProxy.change("mainui", "refreshOnlineBtn", null);
                    break;
                }
                case CMDActivity.GetLiXianExp:
                {
                    _loc_3 = UserData.getOnlineData();
                    _loc_3.lixiantime = param1.getParam();
                    ModelProxy.change("activity", "GetLiXian", param1.getParam() / 3600);
                    ModelProxy.change("mainui", "wdlx", null);
                    ModelProxy.change("mainui", "wdgd", null);
                    break;
                }
                case CMDActivity.RandomQrylRews:
                {
                    _loc_3 = UserData.getOnlineData();
                    _loc_5 = ModelProxy.getValue("data", "logindaycount");
                    _loc_3.dzp = 1;
                    if (_loc_3.dzprews)
                    {
                        _loc_3.dzprews[_loc_5] = param1.getParam();
                    }
                    else
                    {
                        _loc_3.dzprews = new Object();
                        _loc_3.dzprews[_loc_5] = param1.getParam();
                    }
                    ModelProxy.change("dzp", "randomDzp", param1.getParam());
                    break;
                }
                case CMDActivity.InitDzp:
                {
                    _loc_3 = UserData.getOnlineData();
                    _loc_3.dzprews = param1.getParam();
                    ModelProxy.change("dzp", "init", null);
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            var _loc_3:Input = null;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:int = 0;
            var _loc_12:int = 0;
            var _loc_13:Object = null;
            var _loc_14:Object = null;
            var _loc_15:Array = null;
            var _loc_16:int = 0;
            var _loc_17:int = 0;
            var _loc_2:* = new Object();
            _loc_3 = new Input(null);
            var _loc_4:* = param1.getBody();
            param1.getBody().position = 0;
            _loc_3.setBytes(_loc_4);
            switch(param1.getCmd())
            {
                case 24:
                {
                    _loc_2.loginDayCount = _loc_3.readVarInt(false);
                    _loc_2.rewardState = _loc_3.readVarInt(false);
                    ModelProxy.change("data", "qrylInfo", _loc_2);
                    ModelProxy.change("qryl", "success", _loc_2);
                    this.checkReward(_loc_2);
                    break;
                }
                case CMDActivity._30GETTOUZIINFO:
                {
                    _loc_5 = _loc_3.readShort();
                    _loc_2.touziInfo = new Array();
                    _loc_9 = 0;
                    while (_loc_9 < _loc_5)
                    {
                        
                        _loc_10 = _loc_3.readByte();
                        if (_loc_10 != 0)
                        {
                            _loc_2.touziInfo[_loc_9] = new Object();
                            _loc_2.touziInfo[_loc_9].touziType = _loc_3.readVarInt(false);
                            _loc_2.touziInfo[_loc_9].num = _loc_3.readVarInt(false);
                            _loc_11 = _loc_3.readShort();
                            _loc_2.touziInfo[_loc_9].day = new Array();
                            _loc_12 = 0;
                            while (_loc_12 < _loc_11)
                            {
                                
                                _loc_2.touziInfo[_loc_9].day[_loc_12] = _loc_3.readVarInt(false);
                                _loc_12++;
                            }
                            _loc_2.touziInfo[_loc_9].canGetDay = _loc_3.readVarInt(false);
                        }
                        _loc_9++;
                    }
                    ModelProxy.change("touzi", "init", _loc_2.touziInfo);
                    _loc_6 = ConfigDictionary.data.touzi;
                    for each (_loc_13 in _loc_2.touziInfo)
                    {
                        
                        for each (_loc_14 in _loc_6)
                        {
                            
                            if (_loc_14.type == _loc_13.touziType)
                            {
                                if (_loc_14.num == _loc_13.num)
                                {
                                    _loc_15 = _loc_14.reward.split("&");
                                    if (_loc_13.day.length < _loc_15.length)
                                    {
                                        ModelProxy.change("mainui", "addBtn", "touzilicai");
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    break;
                }
                case CMDActivity._26TOUZI:
                {
                    _loc_2.touziType = _loc_3.readVarInt(false);
                    _loc_2.num = _loc_3.readVarInt(false);
                    ModelProxy.change("touzi", "touzi", _loc_2);
                    WarningManager.show(137);
                    break;
                }
                case CMDActivity._28TOUZILINGQU:
                {
                    _loc_2.touziType = _loc_3.readVarInt(false);
                    _loc_2.num = _loc_3.readVarInt(false);
                    _loc_7 = _loc_3.readShort();
                    _loc_2.day = new Array();
                    _loc_16 = 0;
                    while (_loc_16 < _loc_7)
                    {
                        
                        _loc_2.day[_loc_16] = _loc_3.readVarInt(false);
                        _loc_16++;
                    }
                    ModelProxy.change("touzi", "lingqu", _loc_2);
                    break;
                }
                case CMDActivity._33TEMPTATIONMSG:
                {
                    _loc_2.loginDayCount = _loc_3.readVarInt(false);
                    _loc_8 = _loc_3.readShort();
                    _loc_2.items = new Array();
                    _loc_17 = 0;
                    while (_loc_17 < _loc_8)
                    {
                        
                        _loc_2.items[_loc_17] = _loc_3.readVarInt(false);
                        _loc_17++;
                    }
                    ModelProxy.change("data", "temptationInfo", _loc_2);
                    ModelProxy.change("mainui", "updateTemptation", _loc_2);
                    break;
                }
                case CMDActivity.ReturnWeiXinLiBao:
                {
                    _loc_2.state = _loc_3.readVarInt(false);
                    ModelProxy.change("weixin", "changeLiBao", _loc_2);
                    if (_loc_2.state == 1)
                    {
                        ModelProxy.change("mainui", "removeBtn", "weixin");
                    }
                    else if (Config.gameParams.oper == "360" || Config.debug)
                    {
                        ModelProxy.change("mainui", "addBtn", "weixin");
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function checkReward(param1:Object) : void
        {
            var _loc_2:int = 1;
            while (_loc_2 <= param1.loginDayCount)
            {
                
                if (!this.isGetReward(_loc_2, param1.rewardState))
                {
                    ModelProxy.change("mainui", "showEffect", {ab:"qryl", state:true});
                    return;
                }
                _loc_2++;
            }
            ModelProxy.change("mainui", "showEffect", {ab:"qryl", state:false});
            return;
        }// end function

        private function isGetReward(param1:int, param2:int) : Boolean
        {
            var _loc_4:int = 0;
            var _loc_3:* = param1;
            _loc_4 = param2 >> _loc_3;
            var _loc_5:* = _loc_4 % 2 != 0;
            return _loc_4 % 2 != 0;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

    }
}
